#ifndef _TBuffer_H_
#define _TBuffer_H_
#include <map>
#include <vector>
class TBufferPool
{
    //friend class TBuffer;
public:
    TBufferPool();
    virtual ~TBufferPool();

    int AllocBlock();
    void FreeBlock(int blockNo);
    struct STBlock* GetBlock(int blockNo);

private:
    struct STBlock* allBlocks_;
    std::vector<int> noUseBlockNo_;
};

class TBuffer
{
public:
    TBuffer(TBufferPool* pool);
    virtual ~TBuffer();

    bool Read(char* buff, int len, bool del=true);
    bool Write(char* buff, int len);
    void WriteFromSock(int srcfd, int len);

private:
    int readNo_, writeNo_, readIdx_, writeIdx_;
    TBufferPool* bufferPool_;
    std::vector<int> blocks_;
};

#define BLOCK_SIZE	10
#define BLOCK_COUNT	10000


#endif